home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / statistics / minmax_source.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-05  |  3.4 KB  |  146 lines

  1. /* statistics/minmax_source.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Jim Davies, Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20.  
  21. BASE 
  22. FUNCTION(gsl_stats,max) (const BASE data[], const size_t stride, const size_t n)
  23. {
  24.   /* finds the largest member of a dataset */
  25.  
  26.   BASE max = data[0 * stride];
  27.   size_t i;
  28.  
  29.   for (i = 0; i < n; i++)
  30.     {
  31.       if (data[i * stride] > max)
  32.     max = data[i * stride];
  33.     }
  34.  
  35.   return max;
  36. }
  37.  
  38. BASE
  39. FUNCTION(gsl_stats,min) (const BASE data[], const size_t stride, const size_t n)
  40. {
  41.   /* finds the smallest member of a dataset */
  42.  
  43.   BASE min = data[0 * stride];
  44.   size_t i;
  45.  
  46.   for (i = 0; i < n; i++)
  47.     {
  48.       if (data[i * stride] < min)
  49.     min = data[i * stride];
  50.     }
  51.  
  52.   return min;
  53.  
  54. }
  55.  
  56. void
  57. FUNCTION(gsl_stats,minmax) (BASE * min_out, BASE * max_out, const BASE data[], const size_t stride, const size_t n)
  58. {
  59.   /* finds the smallest and largest members of a dataset */
  60.  
  61.   BASE min = data[0 * stride];
  62.   BASE max = data[0 * stride];
  63.   size_t i;
  64.  
  65.   for (i = 0; i < n; i++)
  66.     {
  67.       if (data[i * stride] < min)
  68.     min = data[i * stride];
  69.       if (data[i * stride] > max)
  70.     max = data[i * stride];
  71.     }
  72.  
  73.   *min_out = min ;
  74.   *max_out = max ;
  75. }
  76.  
  77. size_t
  78. FUNCTION(gsl_stats,max_index) (const BASE data[], const size_t stride, const size_t n)
  79. {
  80.   /* finds the index of the largest member of a dataset */
  81.   /* if there is more than one largest value then we choose the first */
  82.  
  83.   BASE max = data[0 * stride];
  84.   size_t i, max_index = 0;
  85.  
  86.   for (i = 0; i < n; i++)
  87.     {
  88.       if (data[i * stride] > max)
  89.     {
  90.       max = data[i * stride];
  91.       max_index = i ;
  92.     }
  93.     }
  94.  
  95.   return max_index;
  96. }
  97.  
  98. size_t
  99. FUNCTION(gsl_stats,min_index) (const BASE data[], const size_t stride, const size_t n)
  100. {
  101.   /* finds the index of the smallest member of a dataset */
  102.   /* if there is more than one largest value then we choose the first  */
  103.  
  104.   BASE min = data[0 * stride];
  105.   size_t i, min_index = 0;
  106.  
  107.   for (i = 0; i < n; i++)
  108.     {
  109.       if (data[i * stride] < min)
  110.     {
  111.       min = data[i * stride];
  112.       min_index = i ;
  113.     }
  114.     }
  115.  
  116.   return min_index;
  117. }
  118.  
  119. void
  120. FUNCTION(gsl_stats,minmax_index) (size_t * min_index_out, size_t * max_index_out, const BASE data[], const size_t stride, const size_t n)
  121. {
  122.   /* finds the smallest and largest members of a dataset */
  123.  
  124.   BASE min = data[0 * stride];
  125.   BASE max = data[0 * stride];
  126.   size_t i, min_index = 0, max_index = 0;
  127.  
  128.   for (i = 0; i < n; i++)
  129.     {
  130.       if (data[i * stride] < min)
  131.         {
  132.           min = data[i * stride];
  133.           min_index = i;
  134.         }
  135.  
  136.       if (data[i * stride] > max)
  137.         {
  138.           max = data[i * stride];
  139.           max_index = i;
  140.         }
  141.     }
  142.  
  143.   *min_index_out = min_index ;
  144.   *max_index_out = max_index ;
  145. }
  146.